package com.yupi.yuoj.model.vo;

import com.yupi.yuoj.model.entity.MembershipOrder;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;
import org.springframework.beans.BeanUtils;

/**
 * 会员订单视图
 *
 * @author jingjin
 */
@Data
public class MembershipOrderVO implements Serializable {

    /**
     * id
     */
    private Long id;

    /**
     * 订单号
     */
    private String orderNumber;

    /**
     * 用户 id
     */
    private Long userId;

    /**
     * 会员套餐 id
     */
    private Long membershipPlanId;

    /**
     * 订单金额
     */
    private BigDecimal amount;

    /**
     * 支付方式（alipay-支付宝, wechat-微信, balance-余额）
     */
    private String paymentMethod;

    /**
     * 订单状态（pending-待支付, paid-已支付, cancelled-已取消）
     */
    private String orderStatus;

    /**
     * 支付时间
     */
    private Date paymentTime;

    /**
     * 过期时间
     */
    private Date expireTime;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 用户信息
     */
    private UserVO user;

    /**
     * 会员套餐信息
     */
    private MembershipPlanVO membershipPlan;

    /**
     * 订单状态文本
     */
    private String statusText;

    /**
     * 支付方式文本
     */
    private String paymentMethodText;

    /**
     * 包装类转对象
     *
     * @param membershipOrderVO
     * @return
     */
    public static MembershipOrder voToObj(MembershipOrderVO membershipOrderVO) {
        if (membershipOrderVO == null) {
            return null;
        }
        MembershipOrder membershipOrder = new MembershipOrder();
        BeanUtils.copyProperties(membershipOrderVO, membershipOrder);
        return membershipOrder;
    }

    /**
     * 对象转包装类
     *
     * @param membershipOrder
     * @return
     */
    public static MembershipOrderVO objToVo(MembershipOrder membershipOrder) {
        if (membershipOrder == null) {
            return null;
        }
        MembershipOrderVO membershipOrderVO = new MembershipOrderVO();
        BeanUtils.copyProperties(membershipOrder, membershipOrderVO);
        
        // 设置状态文本
        if (membershipOrder.getOrderStatus() != null) {
            switch (membershipOrder.getOrderStatus()) {
                case "pending":
                    membershipOrderVO.setStatusText("待支付");
                    break;
                case "paid":
                    membershipOrderVO.setStatusText("已支付");
                    break;
                case "cancelled":
                    membershipOrderVO.setStatusText("已取消");
                    break;
                default:
                    membershipOrderVO.setStatusText("未知状态");
                    break;
            }
        }
        
        // 设置支付方式文本
        if (membershipOrder.getPaymentMethod() != null) {
            switch (membershipOrder.getPaymentMethod()) {
                case "alipay":
                    membershipOrderVO.setPaymentMethodText("支付宝");
                    break;
                case "wechat":
                    membershipOrderVO.setPaymentMethodText("微信支付");
                    break;
                case "balance":
                    membershipOrderVO.setPaymentMethodText("余额支付");
                    break;
                default:
                    membershipOrderVO.setPaymentMethodText("其他");
                    break;
            }
        }
        
        return membershipOrderVO;
    }

    private static final long serialVersionUID = 1L;
}